package com.todo.strategy.offline.application.convert;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.todo.common.common.entity.CurrentStaff;
import com.todo.common.common.entity.response.page.PageResult;
import com.todo.common.common.enums.AllowedCommentEnum;
import com.todo.common.common.enums.BizErrorCodeEnum;
import com.todo.common.common.enums.biz.PrivateTypeEnum;
import com.todo.common.common.exception.BizException;
import com.todo.common.utils.TodoCommonUtils;
import com.todo.strategy.common.enums.*;
import com.todo.strategy.offline.application.entity.bo.*;
import com.todo.strategy.offline.application.entity.condition.PlanSetConditionBO;
import com.todo.strategy.offline.application.entity.condition.PlatformStrategyConditionBO;
import com.todo.strategy.offline.iface.request.*;
import com.todo.strategy.offline.iface.request.QueryPlatformStrategyByConditionReq;
import com.todo.strategy.offline.iface.response.PlatformStrategyDetailResp;
import com.todo.strategy.offline.iface.response.PlatformStrategyRelationItemResp;
import com.todo.strategy.offline.iface.response.PlatformStrategyRelationResp;
import com.todo.strategy.offline.iface.response.QueryPlatformStrategyByConditionResp;
import com.todo.strategy.offline.infrastructure.entity.condition.PlanSetCondition;
import com.todo.strategy.offline.infrastructure.entity.condition.PlatformStrategyCondition;
import com.todo.strategy.offline.infrastructure.entity.po.PlanRelationPO;
import com.todo.strategy.offline.infrastructure.entity.po.PlanSetPO;
import com.todo.strategy.offline.infrastructure.entity.po.PlatformStrategyDetailPO;
import com.todo.strategy.offline.infrastructure.entity.po.PlatformStrategyPO;
import org.apache.commons.collections4.CollectionUtils;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author azhebuxing
 * @date 2025/2/28 00:23
 * @description
 */
public class StrategyConvert {
    public static PlatformStrategyPO convertToPlatformStrategyPO(PlatformStrategyBO platformStrategyBO) {
        if (platformStrategyBO == null) {
            return null;
        }
        PlatformStrategyPO platformStrategyPO = new PlatformStrategyPO();
        platformStrategyPO.setAllowComment(platformStrategyBO.getAllowComment() == null ? null : platformStrategyBO.getAllowComment().getType());
        platformStrategyPO.setCity(platformStrategyBO.getCity());
        platformStrategyPO.setReferenceCount(platformStrategyBO.getReferenceCount());
        platformStrategyPO.setCreateUser(platformStrategyBO.getCreateUser());
        platformStrategyPO.setScore(platformStrategyBO.getScore());
        platformStrategyPO.setProvince(platformStrategyBO.getProvince());
        platformStrategyPO.setStatus(platformStrategyBO.getStatus() == null ? null : platformStrategyBO.getStatus().getType());
        platformStrategyPO.setStrategyType(platformStrategyBO.getStrategyType() == null ? null : platformStrategyBO.getStrategyType().getType());
        platformStrategyPO.setTimeCost(platformStrategyBO.getTimeCost());
        platformStrategyPO.setTravelTimeType(platformStrategyBO.getTravelTimeType() == null ? null : platformStrategyBO.getTravelTimeType().getType());
        platformStrategyPO.setMoneyCost(platformStrategyBO.getMoneyCost());
        platformStrategyPO.setTitle(platformStrategyBO.getTitle());
        platformStrategyPO.setMainImg(platformStrategyBO.getMainImg());
        platformStrategyPO.setIsFree(platformStrategyBO.getIsFree());
        platformStrategyPO.setViewCount(platformStrategyBO.getViewCount());
        platformStrategyPO.setCollectCount(platformStrategyBO.getCollectCount());
        platformStrategyPO.setLikeCount(platformStrategyBO.getLikeCount());
        platformStrategyPO.setCommentCount(platformStrategyBO.getCommentCount());
        platformStrategyPO.setRecommendDesc(platformStrategyBO.getRecommendDesc());
        platformStrategyPO.setRecommendMonth(JSONObject.toJSONString(platformStrategyBO.getRecommendMonth()));
        platformStrategyPO.setLastUpdateUser(platformStrategyBO.getLastUpdateUser());
        platformStrategyPO.setId(platformStrategyBO.getStrategyId() == null ? TodoCommonUtils.buildLongGuid() : platformStrategyBO.getStrategyId());
        platformStrategyPO.setIsDelete(platformStrategyPO.getIsDelete() == null ? 0 : platformStrategyPO.getIsDelete());
        platformStrategyPO.setCreateTime(new Date());
        platformStrategyPO.setUpdateTime(new Date());
        return platformStrategyPO;
    }

    public static PlatformStrategyDetailPO convertToPlatformStrategyDetailPO(PlatformStrategyExtendBO platformStrategyExtendBO) {
        if (platformStrategyExtendBO == null) {
            return null;
        }
        PlatformStrategyDetailPO platformStrategyDetailPO = new PlatformStrategyDetailPO();
        platformStrategyDetailPO.setAgeSuggest(JSONObject.toJSONString(platformStrategyExtendBO.getAgeSuggest()));
        platformStrategyDetailPO.setExtra(JSONObject.toJSONString(platformStrategyExtendBO.getExtra()));
        platformStrategyDetailPO.setInstructions(JSONObject.toJSONString(platformStrategyExtendBO.getInstructions()));
        platformStrategyDetailPO.setSecuritySuggest(JSONObject.toJSONString(platformStrategyExtendBO.getSecuritySuggest()));
        platformStrategyDetailPO.setId(platformStrategyExtendBO.getStrategyId());
        platformStrategyDetailPO.setTravelSuggest(JSONObject.toJSONString(platformStrategyExtendBO.getTravelSuggest()));
        platformStrategyDetailPO.setIsDelete(0);
        platformStrategyDetailPO.setCreateTime(new Date());
        platformStrategyDetailPO.setUpdateTime(new Date());
        return platformStrategyDetailPO;
    }

    public static PlatformStrategyCondition convertToPlatformStrategyCondition(PlatformStrategyConditionBO platformStrategyConditionBO) {
        if (platformStrategyConditionBO == null) {
            return null;
        }
        PlatformStrategyCondition platformStrategyCondition = new PlatformStrategyCondition();
        platformStrategyCondition.setPageSize(platformStrategyConditionBO.getPageSize());
        platformStrategyCondition.setPageIndex(platformStrategyConditionBO.getPageIndex());
        platformStrategyCondition.setStrategyType(platformStrategyConditionBO.getStrategyType() == null ? null :platformStrategyConditionBO.getStrategyType().getType());
        platformStrategyCondition.setStatus(platformStrategyConditionBO.getStatus() == null ? null :platformStrategyConditionBO.getStatus().getType());
        platformStrategyCondition.setTravelTimeType(platformStrategyConditionBO.getTravelTimeType() == null ? null :platformStrategyConditionBO.getTravelTimeType().getType());
        platformStrategyCondition.setIsFree(platformStrategyConditionBO.getIsFree());
        platformStrategyCondition.setCity(platformStrategyConditionBO.getCity());
        platformStrategyCondition.setProvince(platformStrategyConditionBO.getProvince());
        platformStrategyCondition.setTitle(platformStrategyConditionBO.getTitle());
        platformStrategyCondition.setCreateUser(platformStrategyConditionBO.getCreateUser());
        platformStrategyCondition.setCurrentIndex(platformStrategyConditionBO.getCurrentIndex());
        return platformStrategyCondition;
    }

    public static PlatformStrategyBO convertToPlatformStrategyBO(PlatformStrategyPO platformStrategyPO) {
        if (platformStrategyPO == null) {
            return null;
        }
        PlatformStrategyBO platformStrategyBO = new PlatformStrategyBO();
        platformStrategyBO.setAllowComment(AllowedCommentEnum.getByType(platformStrategyPO.getAllowComment()));
        platformStrategyBO.setCity(platformStrategyPO.getCity());
        platformStrategyBO.setReferenceCount(platformStrategyPO.getReferenceCount());
        platformStrategyBO.setCreateUser(platformStrategyPO.getCreateUser());
        platformStrategyBO.setScore(platformStrategyPO.getScore());
        platformStrategyBO.setProvince(platformStrategyPO.getProvince());
        platformStrategyBO.setStatus(StrategyStatusEnum.getByType(platformStrategyPO.getStatus()));
        platformStrategyBO.setStrategyType(StrategyTypeEnum.getByType(platformStrategyPO.getStrategyType()));
        platformStrategyBO.setTimeCost(platformStrategyPO.getTimeCost());
        platformStrategyBO.setTravelTimeType(TravelDayTypeEnum.getByType(platformStrategyPO.getTravelTimeType()));
        platformStrategyBO.setMoneyCost(platformStrategyPO.getMoneyCost());
        platformStrategyBO.setTitle(platformStrategyPO.getTitle());
        platformStrategyBO.setMainImg(platformStrategyPO.getMainImg());
        platformStrategyBO.setIsFree(platformStrategyPO.getIsFree());
        platformStrategyBO.setViewCount(platformStrategyPO.getViewCount());
        platformStrategyBO.setCollectCount(platformStrategyPO.getCollectCount());
        platformStrategyBO.setLikeCount(platformStrategyPO.getLikeCount());
        platformStrategyBO.setCommentCount(platformStrategyPO.getCommentCount());
        platformStrategyBO.setRecommendDesc(platformStrategyPO.getRecommendDesc());
        platformStrategyBO.setRecommendMonth(JSONObject.parseArray(platformStrategyPO.getRecommendMonth(), String.class));
        platformStrategyBO.setLastUpdateUser(platformStrategyPO.getLastUpdateUser());
        platformStrategyBO.setStrategyId(platformStrategyPO.getId());
        platformStrategyBO.setCreateTime(platformStrategyPO.getCreateTime());
        platformStrategyBO.setUpdateTime(platformStrategyPO.getUpdateTime());
        return platformStrategyBO;
    }

    public static PlatformStrategyExtendBO convertToPlatformStrategyExtendBO(PlatformStrategyDetailPO platformStrategyDetailPO) {
        if (platformStrategyDetailPO == null) {
            return null;
        }
        PlatformStrategyExtendBO platformStrategyExtendBO = new PlatformStrategyExtendBO();
        platformStrategyExtendBO.setAgeSuggest(platformStrategyExtendBO.getAgeSuggest());
        platformStrategyExtendBO.setExtra(JSONObject.parseObject(platformStrategyDetailPO.getExtra(), PlatformStrategyExtendBO.Extra.class));
        platformStrategyExtendBO.setInstructions(JSONObject.parseObject(platformStrategyDetailPO.getInstructions(), PlatformStrategyExtendBO.Instructions.class));
        platformStrategyExtendBO.setSecuritySuggest(JSONObject.parseObject(platformStrategyDetailPO.getSecuritySuggest(), PlatformStrategyExtendBO.SecuritySuggest.class));
        platformStrategyExtendBO.setTravelSuggest(JSONObject.parseObject(platformStrategyDetailPO.getTravelSuggest(), PlatformStrategyExtendBO.TravelSuggest.class));
        platformStrategyExtendBO.setStrategyId(platformStrategyDetailPO.getId());
        return platformStrategyExtendBO;
    }

    public static PlanSetPO convertToPlanSetPO(PlanSetBO planSetBO) {
        if (planSetBO == null) {
            return null;
        }
        PlanSetPO planSetPO = new PlanSetPO();
        planSetPO.setId(planSetBO.getPlanId() == null ? TodoCommonUtils.buildLongGuid() : planSetBO.getPlanId());
        planSetPO.setUserId(planSetBO.getUserId());
        planSetPO.setPlanUseTime(planSetBO.getPlanUseTime());
        planSetPO.setPlanMoneySpend(planSetBO.getPlanMoneySpend());
        planSetPO.setPlanType(planSetBO.getPlanType().getType());
        planSetPO.setPlanCity(planSetBO.getPlanCity());
        planSetPO.setEndPlanTime(planSetBO.getEndPlanTime());
        planSetPO.setStartPlanTime(planSetBO.getStartPlanTime());
        planSetPO.setDesc(planSetBO.getDesc());
        planSetPO.setStatus(planSetBO.getStatus() == null ? StrategyStatusEnum.PUBLISHED.getType() : planSetBO.getStatus().getType());
        planSetPO.setExtra(JSONObject.toJSONString(planSetBO.getExtra()));
        planSetPO.setIsPrivate(planSetBO.getIsPrivate().getType());
        planSetPO.setIsTravel(planSetBO.getIsTravel());
        planSetPO.setMainImg(planSetBO.getMainImg());
        planSetPO.setTitle(planSetBO.getTitle());
        planSetPO.setRelationCount(planSetBO.getRelationCount() == null ? 0 : planSetBO.getRelationCount());
        planSetPO.setIsDelete(0);
        planSetPO.setCreateTime(new Date());
        planSetPO.setUpdateTime(new Date());
        return planSetPO;
    }

    public static PlanSetBO convertToPlanSetBO(PlanSetPO planSetPO) {
        if (planSetPO == null) {
            return null;
        }
        PlanSetBO planSetBO = new PlanSetBO();
        planSetBO.setPlanId(planSetPO.getId());
        planSetBO.setUserId(planSetPO.getUserId());
        planSetBO.setPlanUseTime(planSetPO.getPlanUseTime());
        planSetBO.setPlanMoneySpend(planSetPO.getPlanMoneySpend());
        planSetBO.setPlanType(StrategyTypeEnum.getByType(planSetPO.getPlanType()));
        planSetBO.setPlanCity(planSetPO.getPlanCity());
        planSetBO.setEndPlanTime(planSetPO.getEndPlanTime());
        planSetBO.setStartPlanTime(planSetPO.getStartPlanTime());
        planSetBO.setDesc(planSetPO.getDesc());
        planSetBO.setStatus(planSetPO.getStatus() == null ? StrategyStatusEnum.PUBLISHED : StrategyStatusEnum.getByType(planSetPO.getStatus()));
        planSetBO.setExtra(JSONObject.parseObject(planSetPO.getExtra(), PlanSetBO.Extra.class));
        planSetBO.setIsPrivate(PrivateTypeEnum.getByType(planSetPO.getIsPrivate()));
        planSetBO.setIsTravel(planSetPO.getIsTravel());
        planSetBO.setMainImg(planSetPO.getMainImg());
        planSetBO.setTitle(planSetPO.getTitle());
        planSetBO.setRelationCount(planSetPO.getRelationCount());
        planSetBO.setTravelStatus(calTravelStatus(planSetPO.getStartPlanTime(), planSetPO.getEndPlanTime()));
        return planSetBO;
    }

    /**
     * 计算 出行状态 0-未开始 1-进行中 2-已完成
     *
     * @param startPlanTime
     * @param endPlanTime
     * @return
     */
    private static Integer calTravelStatus(Date startPlanTime, Date endPlanTime) {
        Date now = new Date();
        if (now.before(startPlanTime)) {
            return 0;
        }
        if (now.after(endPlanTime)) {
            return 2;
        }
        return 1;
    }

    public static PlanSetCondition convertToPlanSetCondition(PlanSetConditionBO planSetConditionBO) {
        if (planSetConditionBO == null) {
            return null;
        }
        PlanSetCondition planSetCondition = new PlanSetCondition();
        planSetCondition.setPlanType((planSetConditionBO.getPlanType() == null ? null : planSetConditionBO.getPlanType().getType()));
        planSetCondition.setPageIndex(planSetConditionBO.getPageIndex());
        planSetCondition.setPageSize(planSetConditionBO.getPageSize());
        planSetCondition.setCurrentIndex(planSetConditionBO.getCurrentIndex());
        planSetCondition.setStatus(planSetConditionBO.getStatus());
        planSetCondition.setStartPlanTime(planSetConditionBO.getStartPlanTime());
        planSetCondition.setEndPlanTime(planSetConditionBO.getEndPlanTime());
        planSetCondition.setTitle(planSetConditionBO.getTitle());
        planSetCondition.setPlanCity(planSetConditionBO.getPlanCity());
        planSetCondition.setUserId(planSetConditionBO.getUserId());
        planSetCondition.setPlanId(planSetConditionBO.getPlanId());
        return planSetCondition;
    }

    public static PlanRelationPO convertToPlanRelationPO(PlanRelationBO planRelationBO) {
        if (planRelationBO == null) {
            return null;
        }
        PlanRelationPO planRelationPO = new PlanRelationPO();
        planRelationPO.setId(planRelationBO.getId() == null ? TodoCommonUtils.buildLongGuid() : planRelationBO.getId());
        planRelationPO.setExtra(JSONObject.toJSONString(planRelationBO.getExtra()));
        planRelationPO.setRelationId(planRelationBO.getRelationId());
        planRelationPO.setBusinessId(planRelationBO.getBusinessId());
        planRelationPO.setBusinessScene(planRelationBO.getBusinessScene() == null ? null : planRelationBO.getBusinessScene().getType());
        planRelationPO.setRelationType(planRelationBO.getRelationType() == null ? null : planRelationBO.getRelationType().getType());
        planRelationPO.setPlanDay(planRelationBO.getPlanDay());
        planRelationPO.setMoneyCost(planRelationBO.getMoneyCost());
        planRelationPO.setSuggest(JSONObject.toJSONString(planRelationBO.getSuggest()));
        planRelationPO.setTimeCost(planRelationBO.getTimeCost());
        planRelationPO.setTitle(planRelationBO.getTitle());
        planRelationPO.setIsTravel(planRelationBO.getIsTravel() ? 0 : 1);
        planRelationPO.setRelationName(planRelationBO.getRelationName());
        planRelationPO.setStartTime(planRelationBO.getStartTime());
        planRelationPO.setRemark(planRelationBO.getRemark());
        planRelationPO.setIsDelete(0);
        planRelationPO.setCreateTime(new Date());
        planRelationPO.setUpdateTime(new Date());
        return planRelationPO;
    }

    public static PlanRelationBO convertToPlanRelationBO(PlanRelationPO planRelationPO) {
        if (planRelationPO == null) {
            return null;
        }
        PlanRelationBO planRelationBO = new PlanRelationBO();
        planRelationBO.setId(planRelationPO.getId());
        planRelationBO.setExtra(JSONObject.parseObject(planRelationPO.getExtra(), PlanRelationBO.Extra.class));
        planRelationBO.setRelationId(planRelationPO.getRelationId());
        planRelationBO.setBusinessId(planRelationPO.getBusinessId());
        planRelationBO.setBusinessScene(PlanRelationSceneEnum.getByType(planRelationPO.getBusinessScene()));
        planRelationBO.setRelationType(StrategyRelationTypeEnum.getByType(planRelationPO.getRelationType()));
        planRelationBO.setPlanDay(planRelationPO.getPlanDay());
        planRelationBO.setMoneyCost(planRelationPO.getMoneyCost());
        planRelationBO.setSuggest(JSONObject.parseObject(planRelationPO.getSuggest(), PlanRelationBO.Suggest.class));
        planRelationBO.setTimeCost(planRelationPO.getTimeCost());
        planRelationBO.setTitle(planRelationPO.getTitle());
        planRelationBO.setIsTravel(planRelationPO.getIsTravel() == 0);
        planRelationBO.setRelationName(planRelationPO.getRelationName());
        planRelationBO.setStartTime(planRelationPO.getStartTime());
        planRelationBO.setRemark(planRelationPO.getRemark());
        return planRelationBO;

    }

    public static PlatformStrategyDetailResp convertToPlatformStrategyDetailResp(PlatformStrategyDetailBO platformStrategyDetailBO) {
        if (platformStrategyDetailBO == null) {
            return null;
        }
        PlatformStrategyDetailResp resp = new PlatformStrategyDetailResp();
        if (platformStrategyDetailBO.getPlatformStrategyBO() != null) {
            PlatformStrategyBO platformStrategyBO = platformStrategyDetailBO.getPlatformStrategyBO();
            resp.setTitle(platformStrategyBO.getTitle());
            resp.setMainImg(platformStrategyBO.getMainImg());
            resp.setScore(platformStrategyBO.getScore());
            resp.setTimeCost(platformStrategyBO.getTimeCost());
            resp.setMoneyCost(platformStrategyBO.getMoneyCost());
            resp.setIsFree(platformStrategyBO.getIsFree());
            resp.setRecommendDesc(platformStrategyBO.getRecommendDesc());
            resp.setRecommendMonth(platformStrategyBO.getRecommendMonth());
            resp.setTravelTimeType(platformStrategyBO.getTravelTimeType() == null ? null : platformStrategyBO.getTravelTimeType().getType());
            resp.setStrategyType(platformStrategyBO.getStrategyType() == null ? null : platformStrategyBO.getStrategyType().getType());
            resp.setStatus(platformStrategyBO.getStatus() == null ? null : platformStrategyBO.getStatus().getType());
            resp.setAllowComment(platformStrategyBO.getAllowComment() == null ? null : platformStrategyBO.getAllowComment().getType());
            resp.setCreateUser(platformStrategyBO.getCreateUser());
            resp.setCity(platformStrategyBO.getCity());
            resp.setProvince(platformStrategyBO.getProvince());
            resp.setReferenceCount(platformStrategyBO.getReferenceCount());
            resp.setStrategyId(String.valueOf(platformStrategyBO.getStrategyId()));
        }
        if (platformStrategyDetailBO.getPlatformStrategyExtendBO() != null) {
            PlatformStrategyExtendBO platformStrategyExtendBO = platformStrategyDetailBO.getPlatformStrategyExtendBO();
            resp.setAgeSuggest(platformStrategyExtendBO.getAgeSuggest());
            if(platformStrategyExtendBO.getInstructions() != null) {
                PlatformStrategyDetailResp.Instructions instructions = new PlatformStrategyDetailResp.Instructions();
                instructions.setDifficultyLevel(platformStrategyExtendBO.getInstructions().getDifficultyLevel());
                instructions.setLocalCulture(platformStrategyExtendBO.getInstructions().getLocalCulture());
                resp.setInstructions(instructions);
            }
            if (platformStrategyExtendBO.getTravelSuggest() != null) {
                PlatformStrategyDetailResp.TravelSuggest travelSuggest = new PlatformStrategyDetailResp.TravelSuggest();
                travelSuggest.setTravelSuggest(platformStrategyExtendBO.getTravelSuggest().getTravelSuggest());
                travelSuggest.setEssentialItems(platformStrategyExtendBO.getTravelSuggest().getEssentialItems());
                travelSuggest.setSuggestCarry(platformStrategyExtendBO.getTravelSuggest().getSuggestCarry());
                travelSuggest.setSeasonSuggest(platformStrategyExtendBO.getTravelSuggest().getSeasonSuggest());
                travelSuggest.setDisclose(platformStrategyExtendBO.getTravelSuggest().getDisclose());
                resp.setTravelSuggest(travelSuggest);
            }
            if (platformStrategyExtendBO.getSecuritySuggest() != null) {
                PlatformStrategyDetailResp.SecuritySuggest securitySuggest = new PlatformStrategyDetailResp.SecuritySuggest();
                securitySuggest.setAssistance(platformStrategyExtendBO.getSecuritySuggest().getAssistance());
                securitySuggest.setBaseAttention(platformStrategyExtendBO.getSecuritySuggest().getBaseAttention());
                securitySuggest.setOutDoorAttention(platformStrategyExtendBO.getSecuritySuggest().getOutDoorAttention());
                securitySuggest.setTravelLimit(platformStrategyExtendBO.getSecuritySuggest().getTravelLimit());
                resp.setSecuritySuggest(securitySuggest);
            }
            if (platformStrategyExtendBO.getExtra() != null) {
                resp.setImgList(platformStrategyExtendBO.getExtra().getImgList());
            }
        }
        return resp;
    }

    public static PlatformStrategyConditionBO convertToPlatformStrategyConditionBO(QueryPlatformStrategyByConditionReq req) {
        if (req == null) {
            return null;
        }
        PlatformStrategyConditionBO platformStrategyConditionBO = new PlatformStrategyConditionBO();
        platformStrategyConditionBO.setPageIndex(req.getPageIndex());
        platformStrategyConditionBO.setPageSize(req.getPageSize());
        platformStrategyConditionBO.setCurrentIndex(req.getCurrentIndex());
        platformStrategyConditionBO.setTitle(req.getTitle());
        platformStrategyConditionBO.setStrategyType(StrategyTypeEnum.getByType(req.getStrategyType()));
        platformStrategyConditionBO.setTravelTimeType(TravelDayTypeEnum.getByType(req.getTravelTimeType()));
        platformStrategyConditionBO.setCity(req.getCity());
        platformStrategyConditionBO.setProvince(req.getProvince());
        platformStrategyConditionBO.setStatus(StrategyStatusEnum.getByType(req.getStatus()));
        return platformStrategyConditionBO;
    }

    public static PageResult<QueryPlatformStrategyByConditionResp> convertToQueryPlatformStrategyByConditionRespPage(PageResult<PlatformStrategyBO> pageResult) {
        if (pageResult == null) {
            return null;
        }
        if (CollectionUtils.isEmpty(pageResult.getResults())) {
            return PageResult.of(Lists.newArrayList(), pageResult.getPageNum(), pageResult.getPageSize(), pageResult.getTotal());
        }
        PageResult<QueryPlatformStrategyByConditionResp> result = new PageResult<>();
        result.setCurrentIndex(pageResult.getCurrentIndex());
        result.setPageCount(pageResult.getPageCount());
        result.setPageNum(pageResult.getPageNum());
        result.setPageSize(pageResult.getPageSize());
        result.setHasNext(pageResult.isHasNext());
        result.setTotal(pageResult.getTotal());
        result.setResults(convertToQueryPlatformStrategyByConditionRespList(pageResult.getResults()));
        return result;
    }

    public static List<QueryPlatformStrategyByConditionResp> convertToQueryPlatformStrategyByConditionRespList(List<PlatformStrategyBO> results) {
        if (CollectionUtils.isEmpty(results)) {
            return Lists.newArrayList();
        }
        return results.stream().map(StrategyConvert::convertToQueryPlatformStrategyByConditionResp).collect(Collectors.toList());
    }

    public static QueryPlatformStrategyByConditionResp convertToQueryPlatformStrategyByConditionResp(PlatformStrategyBO platformStrategyBO) {
        if (platformStrategyBO == null) {
            return null;
        }
        QueryPlatformStrategyByConditionResp resp = new QueryPlatformStrategyByConditionResp();
        resp.setTitle(platformStrategyBO.getTitle());
        resp.setStrategyType(platformStrategyBO.getStrategyType() == null ? null : platformStrategyBO.getStrategyType().getType());
        resp.setTravelTimeType(platformStrategyBO.getTravelTimeType() == null ? null : platformStrategyBO.getTravelTimeType().getType());
        resp.setStatus(platformStrategyBO.getStatus() == null ? null : platformStrategyBO.getStatus().getType());
        resp.setReferenceCount(platformStrategyBO.getReferenceCount());
        resp.setStrategyId(String.valueOf(platformStrategyBO.getStrategyId()));
        resp.setIsFree(platformStrategyBO.getIsFree());
        resp.setCity(platformStrategyBO.getCity());
        resp.setProvince(platformStrategyBO.getProvince());
        resp.setRecommendMonth(platformStrategyBO.getRecommendMonth());
        resp.setCreateUser(platformStrategyBO.getCreateUser());
        return resp;
    }

    public static PlatformStrategyBO convertToPlatformStrategyBO(InsertPlatformStrategyReq req) {
        if (req == null) {
            return null;
        }
        PlatformStrategyBO platformStrategyBO = new PlatformStrategyBO();
        platformStrategyBO.setTitle(req.getTitle());
        platformStrategyBO.setStrategyType(StrategyTypeEnum.getByType(req.getStrategyType()));
        platformStrategyBO.setTravelTimeType(TravelDayTypeEnum.getByType(req.getTravelTimeType()));
        platformStrategyBO.setRecommendMonth(req.getRecommendMonth());
        platformStrategyBO.setIsFree(req.getIsFree());
        platformStrategyBO.setCity(req.getCity());
        platformStrategyBO.setProvince(req.getProvince());
        platformStrategyBO.setRecommendDesc(req.getRecommendDesc());
        platformStrategyBO.setStatus(StrategyStatusEnum.DRAFT);
        platformStrategyBO.setMainImg(req.getMainImg());
        platformStrategyBO.setScore(req.getScore());
        platformStrategyBO.setTimeCost(req.getTimeCost());
        platformStrategyBO.setMoneyCost(req.getMoneyCost());
        platformStrategyBO.setAllowComment(AllowedCommentEnum.getByType(req.getAllowComment()));
        platformStrategyBO.setViewCount(0);
        platformStrategyBO.setCommentCount(0);
        platformStrategyBO.setLikeCount(0);
        platformStrategyBO.setCollectCount(0);
        CurrentStaff currentStaff = req.get_staff();
        if (currentStaff == null) {
            throw new BizException(BizErrorCodeEnum.INVALID_ACCESS_TOKEN);
        }
        platformStrategyBO.setCreateUser(currentStaff.getUsername());
        platformStrategyBO.setLastUpdateUser(currentStaff.getUsername());
        return platformStrategyBO;
    }

    public static PlatformStrategyBO convertToPlatformStrategyBO(UpdatePlatformStrategyReq req) {
        if (req == null) {
            return null;
        }
        PlatformStrategyBO platformStrategyBO = new PlatformStrategyBO();
        platformStrategyBO.setStrategyId(req.getStrategyId());
        platformStrategyBO.setTitle(req.getTitle());
        platformStrategyBO.setStrategyType(StrategyTypeEnum.getByType(req.getStrategyType()));
        platformStrategyBO.setTravelTimeType(TravelDayTypeEnum.getByType(req.getTravelTimeType()));
        platformStrategyBO.setRecommendMonth(req.getRecommendMonth());
        platformStrategyBO.setIsFree(req.getIsFree());
        platformStrategyBO.setCity(req.getCity());
        platformStrategyBO.setProvince(req.getProvince());
        platformStrategyBO.setRecommendDesc(req.getRecommendDesc());
        platformStrategyBO.setMainImg(req.getMainImg());
        platformStrategyBO.setScore(req.getScore());
        platformStrategyBO.setTimeCost(req.getTimeCost());
        platformStrategyBO.setMoneyCost(req.getMoneyCost());
        platformStrategyBO.setAllowComment(AllowedCommentEnum.getByType(req.getAllowComment()));
        CurrentStaff currentStaff = req.get_staff();
        if (currentStaff == null) {
            throw new BizException(BizErrorCodeEnum.INVALID_ACCESS_TOKEN);
        }
        platformStrategyBO.setLastUpdateUser(currentStaff.getUsername());
        return platformStrategyBO;
    }

    public static PlatformStrategyExtendBO convertToPlatformStrategyExtendBO(AppendPlatformStrategyDetailReq req) {
        if (req == null) {
            return null;
        }
        PlatformStrategyExtendBO platformStrategyExtendBO = new PlatformStrategyExtendBO();
        if (req.getInstructions() != null) {
            AppendPlatformStrategyDetailReq.Instructions originInstructions = req.getInstructions();
            PlatformStrategyExtendBO.Instructions instructions = new PlatformStrategyExtendBO.Instructions();
            instructions.setDifficultyLevel(originInstructions.getDifficultyLevel());
            instructions.setLocalCulture(originInstructions.getLocalCulture());
            platformStrategyExtendBO.setInstructions(instructions);
        }
        platformStrategyExtendBO.setAgeSuggest(req.getAgeSuggest());
        if (req.getSecuritySuggest() != null) {
            AppendPlatformStrategyDetailReq.SecuritySuggest originSecuritySuggest = req.getSecuritySuggest();
            PlatformStrategyExtendBO.SecuritySuggest securitySuggest = new PlatformStrategyExtendBO.SecuritySuggest();
            securitySuggest.setAssistance(originSecuritySuggest.getAssistance());
            securitySuggest.setTravelLimit(originSecuritySuggest.getTravelLimit());
            securitySuggest.setBaseAttention(originSecuritySuggest.getBaseAttention());
            securitySuggest.setOutDoorAttention(originSecuritySuggest.getOutDoorAttention());
            platformStrategyExtendBO.setSecuritySuggest(securitySuggest);
        }
        if (req.getTravelSuggest() != null) {
            AppendPlatformStrategyDetailReq.TravelSuggest originTravelSuggest = req.getTravelSuggest();
            PlatformStrategyExtendBO.TravelSuggest travelSuggest = new PlatformStrategyExtendBO.TravelSuggest();
            travelSuggest.setTravelSuggest(originTravelSuggest.getTravelSuggest());
            travelSuggest.setEssentialItems(originTravelSuggest.getEssentialItems());
            travelSuggest.setSuggestCarry(originTravelSuggest.getSuggestCarry());
            travelSuggest.setSeasonSuggest(originTravelSuggest.getSeasonSuggest());
            travelSuggest.setDisclose(originTravelSuggest.getDisclose());
            platformStrategyExtendBO.setTravelSuggest(travelSuggest);
        }
        platformStrategyExtendBO.setExtra(new PlatformStrategyExtendBO.Extra());
        platformStrategyExtendBO.getExtra().setImgList(req.getImgList());
        platformStrategyExtendBO.setStrategyId(Long.valueOf(req.getStrategyId()));
        return platformStrategyExtendBO;
    }

    public static PlanRelationBO convertToPlanRelationBO(InsertStrategyRelationReq req) {
        if (req == null) {
            return null;
        }
        PlanRelationBO planRelationBO = new PlanRelationBO();
        planRelationBO.setBusinessScene(PlanRelationSceneEnum.PLATFORM_STRATEGY);
        planRelationBO.setTitle(req.getTitle());
        planRelationBO.setPlanDay(req.getPlanDay());
        planRelationBO.setRelationType(StrategyRelationTypeEnum.getByType(req.getRelationType()));
        planRelationBO.setRelationName(req.getRelationName());
        planRelationBO.setRelationId(req.getRelationId());
        planRelationBO.setMoneyCost(req.getMoneyCost());
        planRelationBO.setTimeCost(req.getTimeCost());
        planRelationBO.setStartTime(req.getStartTime());
        if (req.getSuggest() != null) {
            PlanRelationBO.Suggest suggest = new PlanRelationBO.Suggest();
            suggest.setTravelPlan(req.getSuggest().getTravelPlan());
            suggest.setTravelRemark(req.getSuggest().getTravelRemark());
            suggest.setTravelSuggest(req.getSuggest().getTravelSuggest());
            suggest.setNecessaryItems(req.getSuggest().getNecessaryItems());
            planRelationBO.setSuggest(suggest);
        }
        if (StrategyRelationTypeEnum.getByType(req.getRelationType()).equals(StrategyRelationTypeEnum.CUSTOM)) {
            //平台创建的数据不应该存在自定义数据
        }
        planRelationBO.setBusinessId(req.getStrategyId());
        planRelationBO.setIsTravel(false);
        return planRelationBO;
    }

    public static PlanRelationBO convertToPlanRelationBO(UpdateStrategyRelationReq req) {
        if (req == null) {
            return null;
        }
        PlanRelationBO planRelationBO = new PlanRelationBO();
        planRelationBO.setId(req.getId());
        planRelationBO.setBusinessScene(PlanRelationSceneEnum.PLATFORM_STRATEGY);
        planRelationBO.setTitle(req.getTitle());
        planRelationBO.setPlanDay(req.getPlanDay());
        planRelationBO.setRelationType(StrategyRelationTypeEnum.getByType(req.getRelationType()));
        planRelationBO.setRelationName(req.getRelationName());
        planRelationBO.setRelationId(req.getRelationId());
        planRelationBO.setMoneyCost(req.getMoneyCost());
        planRelationBO.setTimeCost(req.getTimeCost());
        planRelationBO.setStartTime(req.getStartTime());
        if (req.getSuggest() != null) {
            PlanRelationBO.Suggest suggest = new PlanRelationBO.Suggest();
            suggest.setTravelPlan(req.getSuggest().getTravelPlan());
            suggest.setTravelRemark(req.getSuggest().getTravelRemark());
            suggest.setTravelSuggest(req.getSuggest().getTravelSuggest());
            suggest.setNecessaryItems(req.getSuggest().getNecessaryItems());
            planRelationBO.setSuggest(suggest);
        }
        if (StrategyRelationTypeEnum.getByType(req.getRelationType()).equals(StrategyRelationTypeEnum.CUSTOM)) {
            //平台创建的数据不应该存在自定义数据
        }
        planRelationBO.setBusinessId(req.getStrategyId());
        //平台攻略默认为true
        planRelationBO.setIsTravel(true);
        return planRelationBO;
    }

    public static List<PlatformStrategyRelationResp> convertToPlatformStrategyRelationRespList(List<PlanRelationBO> planRelationBOS) {
        if (CollectionUtils.isEmpty(planRelationBOS)) {
            return Lists.newArrayList();
        }
        List<PlatformStrategyRelationResp> respList = new ArrayList<>();
        Map<Integer, List<PlanRelationBO>> collect = planRelationBOS.stream().collect(Collectors.groupingBy(PlanRelationBO::getPlanDay));
        for (Integer key : collect.keySet()) {
            respList.add(buildPlatformStrategyRelationResp(key, collect.get(key)));
        }

        return respList;
    }

    private static PlatformStrategyRelationResp buildPlatformStrategyRelationResp(Integer planDay, List<PlanRelationBO> planRelationBOS) {
        if (CollectionUtils.isEmpty(planRelationBOS) || planDay == null) {
            return null;
        }
        PlatformStrategyRelationResp resp = new PlatformStrategyRelationResp();
        resp.setCurrentDay(planDay);
        List<PlatformStrategyRelationResp.DayRelation> dayRelationList = new ArrayList<>();
        for (PlanRelationBO planRelationBO : planRelationBOS) {
            PlatformStrategyRelationResp.DayRelation dayRelation = new PlatformStrategyRelationResp.DayRelation();
            dayRelation.setId(planRelationBO.getId());
            dayRelation.setPlanDay(planRelationBO.getPlanDay());
            dayRelation.setStrategyId(planRelationBO.getBusinessId());
            dayRelation.setRelationName(planRelationBO.getRelationName());
            dayRelation.setTitle(planRelationBO.getRelationName());
            dayRelation.setStartTime(planRelationBO.getStartTime());
            dayRelation.setTimeCost(planRelationBO.getTimeCost());
            dayRelation.setMoneyCost(planRelationBO.getMoneyCost());
            dayRelation.setBusinessScene(planRelationBO.getBusinessScene() == null ? null : planRelationBO.getBusinessScene().getType());
            if (planRelationBO.getSuggest() != null) {
                PlanRelationBO.Suggest originSuggest = planRelationBO.getSuggest();
                PlatformStrategyRelationResp.Suggest suggest = new PlatformStrategyRelationResp.Suggest();
                suggest.setTravelPlan(originSuggest.getTravelPlan());
                suggest.setTravelRemark(originSuggest.getTravelRemark());
                suggest.setTravelSuggest(originSuggest.getTravelSuggest());
                suggest.setNecessaryItems(originSuggest.getNecessaryItems());
                dayRelation.setSuggest(suggest);
            }
            dayRelation.setRelationId(String.valueOf(planRelationBO.getRelationId()));
            dayRelation.setRelationType(planRelationBO.getRelationType() == null ? null : planRelationBO.getRelationType().getType());
            dayRelationList.add(dayRelation);
        }
        //排序
        dayRelationList.sort(Comparator.comparing(PlatformStrategyRelationResp.DayRelation::getStartTime));
        resp.setDayRelation(dayRelationList);
        return resp;
    }

    public static PlatformStrategyRelationItemResp convertToPlatformStrategyRelationItemResp(PlanRelationBO planRelationBO) {
        PlatformStrategyRelationItemResp platformStrategyRelationItemResp = new PlatformStrategyRelationItemResp();
        platformStrategyRelationItemResp.setPlanDay(planRelationBO.getPlanDay());
        platformStrategyRelationItemResp.setRelationId(planRelationBO.getRelationId());
        platformStrategyRelationItemResp.setRelationName(planRelationBO.getRelationName());
        platformStrategyRelationItemResp.setRelationType(planRelationBO.getRelationType() == null ? null : planRelationBO.getRelationType().getType());
        if (planRelationBO.getSuggest() != null) {
            PlatformStrategyRelationItemResp.Suggest respSuggest = new PlatformStrategyRelationItemResp.Suggest();
            respSuggest.setTravelPlan(planRelationBO.getSuggest().getTravelPlan());
            respSuggest.setTravelRemark(planRelationBO.getSuggest().getTravelRemark());
            respSuggest.setTravelSuggest(planRelationBO.getSuggest().getTravelSuggest());
            respSuggest.setNecessaryItems(planRelationBO.getSuggest().getNecessaryItems());
            platformStrategyRelationItemResp.setSuggest(respSuggest);
        }
        platformStrategyRelationItemResp.setTimeCost(planRelationBO.getTimeCost());
        platformStrategyRelationItemResp.setRemark(planRelationBO.getRemark());
        platformStrategyRelationItemResp.setStartTime(planRelationBO.getStartTime());
        platformStrategyRelationItemResp.setId(planRelationBO.getId());
        platformStrategyRelationItemResp.setStrategyId(planRelationBO.getBusinessId());
        platformStrategyRelationItemResp.setTitle(planRelationBO.getTitle());
        platformStrategyRelationItemResp.setMoneyCost(planRelationBO.getMoneyCost());
        return platformStrategyRelationItemResp;
    }
}
